package oj;

import java.util.Scanner;

/**
 * @author LiangYaoYun
 */
public class Main {
    private Node head;
    private int size;
    public static class Node{
        Integer data;
        Node next;
        Node pre;
        Node(){

        }
        Node(Integer data){
            this.data= data;
        }
    }
    private void add(Integer data){
        Node node=new Node(data);
        if (head==null){
            head=node;
            size++;
            return;
        }
        Node n=head;
        while (n.next!=null){
            n=n.next;
        }
        node.pre=n;
        n.next=node;
        node.next=null;
        size++;
    }
    public void length(){
        System.out.println(size+" ");
    }
    public void reverse(){
        Node node=head;
        while (node.next!=null){
            node=node.next;
        }
        while (node!=null){
            System.out.print(node.data+" ");
            node=node.pre;
        }
        System.out.println();
    }
    public void remove(int data){
        int count=0;
        Node node=head;
        while (node!=null){
            if (node.data==data){
                /*头节点判断*/
                if (count==0) {
                    node = node.next;
                }
                Node pre=node.pre;
                Node next=node.next;
                pre.next=next;
                next.pre=pre;
                size--;
            }
            count++;
            node=node.next;
        }
        Node out=head;
        while (out.next!=null){
            System.out.print(out.data+" ");
            out=out.next;
        }
        System.out.print(out.data);
    }
    /*A*/
/*    public static void main(String[] args) {
        Main main = new Main();
        Scanner scanner = new Scanner(System.in);
        String[] str = scanner.nextLine().split(" ");
        scanner.close();
        for (String s : str) {
            main.add(Integer.parseInt(String.valueOf(s)));
        }
        main.length();
        main.reverse();
    }
    */
    /*B*/
/*    public static void main(String[] args) {
        Main main = new Main();
        Scanner scanner = new Scanner(System.in);
        int i=scanner.nextInt();
        for (int j = 0; j < i; j++) {
            int o=scanner.nextInt();
            main.add(o);
        }
        int targer=scanner.nextInt();
        main.remove(targer);

    }*/

    /*C*/
    public static void main(String[] args) {
        Main main = new Main();
        Scanner scanner = new Scanner(System.in);
        String[] str = scanner.nextLine().split(" ");
        scanner.close();
        for (String s : str) {
            main.add(Integer.parseInt(String.valueOf(s)));
        }
        int[] a=new int[100];
        int[] b=new int[100];
        int i=0,j=0;
        while (main.head!=null){
            if (main.head.data>=0){
                b[j]=main.head.data;
                j++;
            }else {
                a[i]=main.head.data;
                i++;
            }
            main.head=main.head.next;
        }
        for (int k = 0; k < j; k++) {
            System.out.print(b[k]+" ");
        }
        System.out.println();
        for (int k = 0; k < i; k++) {
            System.out.print(a[k]+" ");
        }
        System.out.println();
    }
}